#include <vector>
#include <array>
#include <numeric>
using namespace std;
class Solution
{
public:
    int findSubstringInWraproundString(string s)
    {
        // 状态表示dp[i] 以i结尾的所有子串有多少再base出现
        // 画图分析状态转移
        vector<int> dp(s.size(), 1);
        // 去重用哈希
        array<int, 26> count;
        count.fill(0);
        dp[0] = 1;
        count[s[0] - 'a'] = 1;
        for (int i = 1; i < s.size(); i++)
        {
            if (s[i] == s[i - 1] + 1 || s[i] == 'a' && s[i - 1] == 'z')
                dp[i] = dp[i - 1] + 1;
            count[s[i] - 'a'] = max(dp[i], count[s[i] - 'a']);
        }
        return accumulate(count.begin(), count.end(), 0);
    }
};